<template>
	<view class="parent">
		<view class="login-title">账号注册</view>

		<view class="login-input">
			<view class="label"> +86 </view>
			<input class="et" placeholder="请输入手机号" v-model="account" />
		</view>
		<view class="login-input">
			<view class="label"> 验证码 </view>
			<input class="et" placeholder="请输入验证码" v-model="code" />
			<zy-button-code :account='account' :smstype="1"></zy-button-code>
		</view>
		<view class="login-input">
			<view class="label"> 密码 </view>
			<input class="et" placeholder="请输入密码" v-model="password" password/>
		</view>
		<view class="login-input">
			<view class="label"> 邀请码 </view>
			<input class="et" placeholder="请输入邀请码" v-model="inviteCode" password/>
		</view>

		<zy-button text="立即注册" @click.native="onRegister" style="margin-top: 100rpx;"></zy-button>
		<zy-privacy ref="privacy"></zy-privacy>
	</view>
</template>

<script>
	import LoginUtil from '@/main/common/LoginUtil.js';
	import md5 from '@/main/common/md5.js';

	export default {
		data() {
			return {
				account: '',
				code: '',
				password: '',
				inviteCode: '',
			}
		},
		methods: {
			async onRegister() {
				if (!this.$refs.privacy.value()) {
					this.$common.showToast('请勾选隐私政策')
					return
				}
				let param = {
					loginname: this.account,
					code: this.code,
					password: md5.hex_md5(this.password),
					loginType: '2',
					invitationcode: this.inviteCode,
				};
				let res = await this.$common.post('/app/login/login', param);
				if (0 == res.code) {
					LoginUtil.saveToken(res.data.token)
					LoginUtil.login(res)
				} else {
					this.$common.showToast(res.message)
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.parent {
		background-color: #f5f5f5;
		height: 100vh;
		padding: 0 50rpx;

		.login-title {
			color: #222;
			font-size: 50rpx;
			font-weight: bold;
			margin-top: 80rpx;
		}

		.login-input {
			display: flex;
			flex-direction: row;
			align-items: center;
			background-color: #ededed;
			border-radius: 10rpx;
			height: 90rpx;
			margin-top: 50rpx;

			.label {
				width: 150rpx;
				height: 100%;
				line-height: 90rpx;
				font-size: 36rpx;
				color: #222;
				text-align: center;
				margin: auto 0;
			}

			.et {
				height: 100%;
				padding: 0 20rpx;
				font-size: 28rpx;
				flex: 1;
			}
		}

	}
</style>